﻿/*$(document).ready(function() {
	$("#ContentArray").dialog({
		autoOpen : false,
		module : true,
		width : 380,
		buttons : {
			确定 : function() {
				getOrderContent();
			}
		},
		overlay : {
			opacity : 0.5,
			background : "black",
			overflow : 'auto'
		},
		modal : true,
		hide : "fadeout",
		module : true
	});
});*/
var f = new Array();
function changChecked() {
	var obj = document.getElementById("selectDefault");
	if (obj.checked) {
		// 选中的动作
		if($("#showusersNamea1").html()==""||$("#showusersNamea1").html()=='null'){
			alert("请在右上角处登录，登陆后可以填出您的默认地址");
			$("#login_level").show("slow");
			obj.checked=false;
		}else{
			$.getJSON("getSessionCustomer.action",function(data){
				document.getElementById("address").value = data.user.userAddress;
				document.getElementById("telephone").value = data.user.userMobilePhone;
				document.getElementById("username").value = data.user.userRealName;
				setArea(data.user.userProvince,data.user.userCity,data.user.userArea);
				var phone1=data.user.usertelePhone;
				//alert(phone1);
				if(phone1!="-"&&phone1!=""&&phone1!='null'&&phone1!=null){
					document.getElementById("specialplane1").value=phone1.split("-")[0];
					document.getElementById("specialplane2").value=phone1.split("-")[1];
				}
				document.getElementById("username").style.color = "#000000";
			});
		}
	} else {
		// 取消选中的动作
		document.getElementById("address").value = "";
		document.getElementById("telephone").value = "";
		document.getElementById("username").value = "写收件人真实姓名";
		document.getElementById("username").style.color = "#8a8a8a";
	}
}
function checkAll() {
	var obj = document.getElementById("checkAllbox");
	var cb1 = document.getElementsByName("checkbox1");
	if (obj.checked) {
		for ( var i = 0; i < cb1.length; i++) {
			cb1[i].checked = true;
		}
	} else {
		for ( var i = 0; i < cb1.length; i++) {
			cb1[i].checked = false;
		}
	}
}
function usernameFocus() {
	var tele = document.getElementById("username");
	if (tele.value == "写收件人真实姓名") {
		tele.value = "";
	}
	tele.style.color = "#000000";
}
function checkUsername() {
	var tele = document.getElementById("username").value;
	if (tele != null && tele != "写收件人真实姓名" && tele != "") {
		document.getElementById("usernameMsg").innerHTML = "√";
		f[1] = 1;
	} else {
		document.getElementById("usernameMsg").innerHTML = "×";
		document.getElementById("username").style.color = "#8a8a8a";
		document.getElementById("username").value = "写收件人真实姓名";
	}
}
function checkAddress() {
	var tele = document.getElementById("address").value;
	if (tele != null) {
		document.getElementById("addressMsg").innerHTML = "√";
		f[2] = 1;
	} else {
		document.getElementById("addressMsg").innerHTML = "×";
	}
}
function checkMobile() {
	var tele = document.getElementById("telephone").value;
	if (!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(tele))) {
		document.getElementById("telephoneMsg").innerHTML = "×";
	} else {
		document.getElementById("telephoneMsg").innerHTML = "√";
		f[3] = 1;
	}
}
function checkPhone() {
	var tele1 = document.getElementById("specialplane1").value;
	var tele2 = document.getElementById("specialplane2").value;
	if (!(/^\d{2,4}-\d{8}$/.test(tele1 + "-" + tele2))) {
		document.getElementById("specialplaneMsg").innerHTML = "×";
	} else {
		document.getElementById("specialplaneMsg").innerHTML = "√";
		f[4] = 1;
	}
}
function mailFocus() {
	var tele = document.getElementById("mail");
	if (tele.value == "写6位邮政编码") {
		tele.value = "";
	}
	tele.style.color = "#000000";
}
function checkMail() {
	var tele = document.getElementById("mail").value;
	if (!(/^[1-9][0-9]{5}$/.test(tele))) {
		document.getElementById("mailMsg").innerHTML = "×";
		document.getElementById("mail").style.color = "#8a8a8a";
		document.getElementById("mail").value = "写6位邮政编码";
	} else {
		document.getElementById("mailMsg").innerHTML = "√";
		f[5] = 1;
	}
}
var readyToBuy = 0;
function checkAllInput() {
	checkUsername();
	checkAddress();
	checkMobile();
	checkPhone();
	checkMail();
	if (f[1] == f[2] == f[3] == f[5] == 1) {
		document.getElementById("username").disabled = true;
		document.getElementById("address").disabled = true;
		document.getElementById("telephone").disabled = true;
		document.getElementById("mail").disabled = true;
		document.getElementById("selProvance").disabled = true;
		document.getElementById("selCity").disabled = true;
		document.getElementById("selArea").disabled = true;
		document.getElementById("makeSure1").style.display = "none";
		document.getElementById("makeSure2").style.display = "";
		readyToBuy = 1;
		if (f[4] == 1) {
			document.getElementById("specialplane1").disabled = true;
			document.getElementById("specialplane2").disabled = true;
		}
	} else {
		alert("请填写完整、正确");
	}
}
function backToCheck() {
	document.getElementById("username").disabled = false;
	document.getElementById("address").disabled = false;
	document.getElementById("telephone").disabled = false;
	document.getElementById("specialplane1").disabled = false;
	document.getElementById("specialplane2").disabled = false;
	document.getElementById("mail").disabled = false;
	document.getElementById("selProvance").disabled = false;
	document.getElementById("selCity").disabled = false;
	document.getElementById("selArea").disabled = false;
	readyToBuy = 0;
	document.getElementById("makeSure1").style.display = "";
	document.getElementById("makeSure2").style.display = "none";
}
function checkNumber(id) {
	var number = document.getElementsByName("buyCount");

	for ( var n = 0; n < number.length; n++) {
		if (!(/^\d{1,}$/.test(number[n].value))) {
			number[n].value = "1";
			alert("请输入数字!");
		}else{
			var price=$("#"+id+"priceid").val();
			var p=price*number[n].value;
			$("#"+id+"jiageid").html(price*number[n].value+".0元");
		}
	}
}
/*
 * function getOrderContent() { content_bak =
 * document.getElementsByName("ordercontent");
 * document.getElementById("updateCustomForm").submit(); //saveOrder(); }
 */
/*
 * function saveOrder() { 多条订单的公共信息 var username =
 * document.getElementById("username").value;// 收货人的真实姓名 var address =
 * document.getElementById("address").value; var mail =
 * document.getElementById("mail").value; var specialplane =
 * document.getElementById("specialplane1").value + "-" +
 * document.getElementById("specialplane2").value; var telephone =
 * document.getElementById("telephone").value; var province =
 * document.getElementById("selProvance").value.substring(6); var city =
 * document.getElementById("selCity").value.substring(6); var area =
 * document.getElementById("selArea").value; var detail =
 * document.getElementById("hiddendetail" + 0).value; var shoppicture =
 * document.getElementById("shoppingcarpicture").src; var theme =
 * document.getElementById("orderthemearray").value;
 * 
 * 单条信息
 * 
 * var checkedMeg = document.getElementsByName("checkbox1");// 先获得多选框信息 var
 * IDmsg_bak = document.getElementsByName("IDmsg");// ID信息，第一位是0：Custom //
 * 1：Order var number_bak = document.getElementsByName("buyCount");// 购买数量
 * 
 * var IDmsg = new Array(); var number = new Array(); var content = new Array();
 * 
 * var flagAtShopp = 0; for ( var rr = 0; rr < checkedMeg.length; rr++) { if
 * (checkedMeg[rr].checked) { IDmsg[flagAtShopp] = IDmsg_bak[rr].value;
 * number[flagAtShopp] = number_bak[rr].value; content[flagAtShopp] =
 * content_bak[rr].value; flagAtShopp++; } } window.location.href =
 * "updateCustomAtShop.action?customIdArr=" + IDmsg + "&numberArr=" + number +
 * "&username=" + username + "&address=" + address + "&mail=" + mail +
 * "&specialplane=" + specialplane + "&telephone=" + telephone + "&province=" +
 * province + "&city=" + city + "&area=" + area + "&contentArray=" + content +
 * "&ShoppingCarDetail=" + detail + "&shoppicture=" + shoppicture +
 * "&shoptheme=" + theme; }
 */
function reDesignAtShoppingCar(id) {
	window.location.href="showCustom.action?customId="+id;
	/*var detail = document.getElementById("hiddendetail" + id).value;
	customcontent = document.getElementById("contentAtshop").value;
	customname = document.getElementById("orderthemearray").value;
	window.location.href = "showCustom.action?ShoppingCarDetail=" + detail
			+ "&customcontent=" + customcontent + "&customname=" + customname;*/
}